<template>
    <transition name="modal">
        <div class="modal-mask">
            <div class="modal-wrapper">
                <div class="modal-container">
    
                    <div class="modal-header">
                        <div class="row">
                            <div class="col-lg-3">
                                <h3>静态检测结果</h3>
                            </div>
                            <div class="col-lg-9 text-right">
                                <span><b>md5：</b>{{sample.sample_hash}}</span>&nbsp;&nbsp;&nbsp;
                                <span><b>程序名：</b>{{sample.program_name}}</span>&nbsp;&nbsp;&nbsp;
                                &nbsp;&nbsp;&nbsp;
                            </div>
                        </div>
                        
                        <button type="button" class="close" @click="$emit('close')">
                            <i class="fa fa-times" aria-hidden="true"></i>
                        </button>
                    </div>
    
                    <div class="modal-body">
                        <div class="row m-b">
                            <div class="col-lg-1"><b>序号</b></div>
                            <div class="col-lg-6"><b>检测项</b></div>
                            <div class="col-lg-2"><b>检测结果</b></div>
                            <div class="col-lg-3"><b>病毒名</b></div>
                        </div>
                        <div class="list-box">
                            <template v-for="(analysis,i) in res_list">
                                <div class="row m-b" :key="i">
                                    <div class="col-lg-1">{{i+1}}</div>
                                    <div class="col-lg-6">{{analysis.name}}</div>
                                    <div class="col-lg-2">
                                        <button class="btn" :disabled="!analysis.editing" @click.prevent="chgState(analysis)"
                                            :class="{'btn-success':analysis.state_editing==='1','btn-default':analysis.state_editing!=='1'}">
                                            是
                                        </button>
                                    </div>
                                    <div class="col-lg-3" v-if="analysis.case_id=='virus'">
                                        <a href="###" @click.prevent="analysis.editing=true" v-show="!analysis.editing">{{analysis.virus?analysis.virus:'修改'}}</a>
                                        <div class="input-group" v-show="analysis.editing">
                                            <input type="text" class="form-control" v-model="analysis.virus_editing">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-success" @click.prevent="analysisEditConfirm(analysis)">
                                                    <i class="fa fa-check"></i>
                                                </button>
                                                <button type="button" class="btn btn-danger" @click.prevent="analysisEditCancel(analysis)">
                                                    <i class="fa fa-close"></i>
                                                </button>
                                            </span>
                                        </div>
                                    </div>
                                    <div class="col-lg-3" v-else>
                                        {{analysis.virus_editing}}
                                    </div>
                                </div>
                            </template>
                        </div>
                        
                    </div>
    
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" @click="$emit('close')">
                        关闭
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </transition>
</template>
<script>
import {tip,ajax} from '../tools/tools.js'

export default {
    name: 'StaticModal',
    data() {
        return {
            res_list:[]
        }
    },
    props:{
        sample:{
            type:Object,
            default:{}
        }
    },
    watch:{
        sample:{
            deep:true,
            handler(v,ov){
                var self = this;
                if(v.sample_hash){
                    self.resultView();
                }
            }
        }
    },
    methods: {
        resultView(){
            var self = this;
            ajax.getTestResult({
                param:{
                    sample_hash:self.sample.sample_hash,
                    test_type:'1'
                },
                cb(data){
                    data.data.map((v,i)=>{
                        v.virus_editing = v.virus;
                        v.state_editing = v.state;
                        v.editing = false;
                        return v;
                    })
                    self.res_list = data.data;
                }
            })
        },
        chgState(analysis){
            if(analysis.state_editing=='1'){
                analysis.state_editing = '0';
            } else {
                analysis.state_editing = '1';
            }
        },
        analysisEditConfirm(analysis){
            var self = this;
            
            ajax.editVirus({
                param:{
                    sample_hash:self.sample.sample_hash,
                    state:analysis.state_editing,
                    virus:analysis.virus_editing
                },
                cb(data){
                    analysis.state = analysis.state_editing;
                    analysis.virus = analysis.virus_editing;
                    analysis.editing = false;
                    self.$emit('staticdone');
                }
            })
        },
        analysisEditCancel(analysis){
            var self = this;
            analysis.state_editing = analysis.state;
            analysis.virus_editing = analysis.virus;
            analysis.editing = false;
        }
    },
    mounted() {
    }
}
</script>
<style scoped>
.list-box{
    max-height: calc( 100vh - 360px );
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 10px;
}

.close {
    position: absolute;
    right: 30px;
    top: 30px;
}

.modal-mask {
    position: fixed;
    z-index: 10001;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-color: rgba(0, 0, 0, .5);
    transition: opacity .3s ease;
}

.modal-wrapper {
    position: absolute;
    width: 100%;
    height: 1px;
    left: 0;
    right:0;
    top: 120px;
}

.modal-container {
    width: 1100px;
    margin: 0px auto;
    padding: 20px 30px;
    background-color: #fff;
    border-radius: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .33);
    transition: all .3s ease;
    font-family: Helvetica, Arial, sans-serif;
    position: relative;
}

.modal-header h3 {
    margin-top: 0;
    color: #42b983;
}

.modal-default-button {
    float: right;
}

.modal-enter {
    opacity: 0;
}

.modal-leave-active {
    opacity: 0;
}

.modal-enter .modal-container,
.modal-leave-active .modal-container {
    -webkit-transform: scale(1.1);
    transform: scale(1.1);
}
</style>
